package com.funtl.apache.dubbo.transaction.service.impl;

import com.funtl.apache.dubbo.provider.api.domain.TbOrder;
import com.funtl.apache.dubbo.provider.api.service.api.TbOrderService;
import com.funtl.apache.dubbo.provider.item.api.domain.TbOrderItem;
import com.funtl.apache.dubbo.provider.item.api.service.api.ItemService;
import com.funtl.apache.dubbo.transaction.api.service.api.DubboTransactionService;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;

@Service(version = "1.0.0", timeout = 50000)
public class DubboTransactionServiceImpl implements DubboTransactionService {

    @Reference(version = "1.0.0")
    private TbOrderService tbOrderService;

    @Reference(version = "1.0.0")
    private ItemService itemService;

    @Override
    @GlobalTransactional
    public void create() {
        TbOrderItem orderItem = new TbOrderItem();
        orderItem.setUserId(1);
        orderItem.setOrderId(1000);
        orderItem.setOrderItemId(1);

        TbOrder order = new TbOrder();
        order.setUserId(1);
        order.setOrderId(1000);

        itemService.insert(orderItem);
        tbOrderService.insert(order);
    }
}
